﻿HTMLEmail_OnClick = function(){
    var load = $id("load_HTMLEmail");
    var mode = trim($id("lnkedit_HTMLEmail").innerHTML);
    
    StartLoadingAnimation(load);
    
    if(mode == "save")
    {
        if(confirm("save changes?"))
        {
            cbkHTMLEmail_c.PerformCallback(mode + DELIMITER + hteHTMLEmail_c.GetHtml());
        }
        else
        {
            EndLoadingAnimation(load);
            return;
        }
    }
    else if(mode == "edit")
    {
        cbkHTMLEmail_c.PerformCallback(mode);        
    }
}

cbkHTMLEmail_c_CallbackComplete = function(e){
    var div = $id("div_HTMLEmail");
    var load = $id("load_HTMLEmail");
    var dscd = $id("lnkdscd_HTMLEmail");
    var lnk = $id("lnkedit_HTMLEmail");
    var cnt = $id("cnt_HTMLEmail");
    var edt = $id("edt_HTMLEmail");

    EndLoadingAnimation(load);

    var content = e.result;
    
    if(e.parameter == "edit")
    {
        lnk.innerHTML = "save";
        dscd.style.display = "block";
        cnt.style.display = "none";
        edt.style.height = "auto";
        edt.style.width = "auto";
        edt.style.overflow = "";
        hteHTMLEmail_c.SetHtml(content)
    }
    else
    {
        lnk.innerHTML = "edit";
        dscd.style.display = "none";
        cnt.style.display = "block";
        edt.style.height = "0px";
        edt.style.width = "0px";
        edt.style.overflow = "hidden";
        cnt.innerHTML = content;
    }
}

HTMLEmail_Discard = function(){
    if(confirm("discard changes?"))
    {
        var mode = "discard";
        var load = $id("load_HTMLEmail");
        
        StartLoadingAnimation(load);
        
        cbkHTMLEmail_c.PerformCallback(mode);
    }
    else
    {
        EndLoadingAnimation(load);
        return;
    }
}

PlainEmail_OnClick = function(){
    var load = $id("load_PlainEmail");
    var mode = trim($id("lnkedit_PlainEmail").innerHTML);
    var plain = $id("UFT.PLAINMAIL");
    StartLoadingAnimation(load);
    
    if(mode == "save")
    {
        if(confirm("save changes?"))
        {
            cbkPlainEmail_c.PerformCallback(mode + DELIMITER + plain.value);
        }
        else
        {
            EndLoadingAnimation(load);
            return;
        }
    }
    else if(mode == "edit")
    {
        cbkPlainEmail_c.PerformCallback(mode);        
    }
}

cbkPlainEmail_c_CallbackComplete = function(e){
    var div = $id("div_PlainEmail");
    var load = $id("load_PlainEmail");
    var dscd = $id("lnkdscd_PlainEmail");
    var lnk = $id("lnkedit_PlainEmail");
    var cnt = $id("cnt_PlainEmail");
    var edt = $id("edt_PlainEmail");

    EndLoadingAnimation(load);

    var content = e.result;
    
    if(e.parameter == "edit")
    {
        lnk.innerHTML = "save";
        dscd.style.display = "block";
        cnt.style.display = "none";
        edt.style.height = "auto";
        edt.style.width = "auto";
        edt.style.overflow = "";
        hteHTMLEmail_c.SetHtml(content)
    }
    else
    {
        lnk.innerHTML = "edit";
        dscd.style.display = "none";
        cnt.style.display = "block";
        edt.style.height = "0px";
        edt.style.width = "0px";
        edt.style.overflow = "hidden";
        cnt.innerHTML = content;
    }
}

PlainEmail_Discard = function(){
    if(confirm("discard changes?"))
    {
        var mode = "discard";
        var load = $id("load_PlainEmail");
        
        StartLoadingAnimation(load);
        
        cbkPlainEmail_c.PerformCallback(mode);
    }
    else
    {
        EndLoadingAnimation(load);
        return;
    }
}

toggle = function (fsid)
{
    var div = $id("div_" + fsid);
    var ld = $id("lnkdscd_" + fsid);
    var le = $id("lnkedit_" + fsid);
    
    var display = "";
    
    if( div.style.display != "none" )
    {
        display = "none";
    }
    
    div.style.display = display;
    
    if( le != null )
    {
        le.style.display = display;
    }
    
    if( ld == null )
    {
        return;
    }
    
    if( trim(le.innerHTML) == "edit" )
    {
        ld.style.display = "none";
    }
    else
    {
        ld.style.display = display;
    }
}

StartLoadingAnimation = function(div){
    div.innerHTML = "<img src='" + LOADING.src + "' alt='' />";    
}

EndLoadingAnimation = function(div){
    div.innerHTML = "";    
}

closeEditor = function(){
    window.location.reload(true);}